package thread;
// 自定义线程类，继承Thread类
class MyThread extends Thread {
    private String threadName;

    // 构造函数
    public MyThread(String name) {
        this.threadName = name;
        System.out.println("创建线程: " + name);
    }

    // 重写run()方法，定义线程执行的任务
    @Override
    public void run() {
        System.out.println("运行线程: " + threadName);
        try {
            for(int i = 1; i <= 5; i++) {
                System.out.println("线程 " + threadName + ": " + i);
                // 让线程睡眠一段时间
                Thread.sleep(500);
            }
        } catch (InterruptedException e) {
            System.out.println("线程 " + threadName + " 被中断");
        }
        System.out.println("线程 " + threadName + " 退出");
    }
}